﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.IO;

namespace ServidorCanabalt
{
    class Server
    {
        static bool serverLigado = true;

        static void Main(string[] args)
        {
            TcpClient client = null;
            TcpListener listener = null;
            GameState gameState = new GameState();

            try
            {
                IPAddress localAddr = IPAddress.Parse("127.0.0.1");
                listener = new TcpListener(localAddr, 8001);
                listener.Start();

                while (serverLigado)
                {
                    if (gameState.isReady() == false)
                    {
                        Console.WriteLine("Aguardando Conexões...");
                    }

                    client = listener.AcceptTcpClient();
                    gameState.addPlayer(client);
                }
            }
            catch (SocketException e)
            {
                Console.WriteLine("Erro de rede: {0}", e);
            }

            Console.ReadLine();
        }
    }
}
